﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ChatClient
{
    public partial class FormChatWithFriend : Form
    {
        string frname;
        string myname;
        private delegate void UpdateLogCallback(string strMessage);
        public FormChatWithFriend(String myname,String friendname)
        {
            
            InitializeComponent();
            this.frname = friendname;
            this.myname = myname;
            init();
        }
        private void init()
        {
            lbnamefriend.Text = frname;
            this.Text = myname;
        }

        private void btnSend_Click(object sender, EventArgs e)
        {
            SendMessage();
        }
        private void SendMessage()
        {
            
            if (txtChatFriend.Lines.Length >= 1)
            {
                UpdateLog("me",txtChatFriend.Text);
                
               Form1.swSender.WriteLine("%cfr%"+this.frname+"@"+txtChatFriend.Text);
                Form1.swSender.Flush();
                txtChatFriend.Lines = null;
            }
            txtChatFriend.Text = "";
            
        }
        public void UpdateLog(string from,string strMessage)
        {
            // Append text also scrolls the TextBox to the bottom each time
            txtMessageFriend.AppendText(from+" : "+strMessage + "\r\n");
        }

        private void FormEventClosing(object sender, FormClosingEventArgs e)
        {
            this.Visible = false;
            e.Cancel = true;
        }

 
    }
}
